from xml.etree.ElementTree import Element, SubElement, dump, parse, ElementTree, XML
from os.path import dirname
from os import chdir

class BoardGenerator():
    """ this is the class that handles creating a new board out of allowed values or
    creating the xml used to create the board """



    def XMLInit(self):
        ''' init an XML file to start before filling it with stuff '''
        self.root = Element("root")
        self.init = SubElement(self.root, "init")

    def XMLAddBoard(self, level, description, allowed, disallowed):
        ''' add a board, keyed on level
            description = string of what this is
            allowed == list of allowed values
            disallowed == list of disallowed values
            
            YOU MUST CALL XMLInit FIRST!!!!!!!!
        '''
        board = SubElement(self.init, "board") #create board subelement

        SubElement(board, "level").text = str(  level  )   # ID ... should be INT
        SubElement(board, "description").text = str(  description  )
        SubElement(board, "allowed").text = repr(allowed)
        SubElement(board, "disallowed").text = repr(disallowed)


    def XMLWrite(self, filename):
        ''' create the board XML file that has the stuff used to generate the board when loaded
            call XMLInit first,
            then call a series of XMLAddBoard
            
            
            IF filename is a relative path, it writes starting at current directory
            IF filename is an absolute path, it'll write it there
        '''
        dump(self.root)   #DEBUG TO SHOW WHAT IS GOING TO BE WRITTEN
        
        #change to current directory
        chdir(dirname(__file__))
        # write file
        ElementTree(self.root).write(filename)

# factors 2 3 6
# multiples of 3 = 3 6 9 ...
#ineuqality
#equality (4+2) = 6
#nouns
#verbs
# primes 2 3 7 11
# mammals
